### conative attitudes matrix showing action/inaction pairs

Passive_Option <- c("tutor","headmaster","wait","send")

##ENDLINE
#Subset endline data to compliers only and relevant variables, note that randomdraw6_grouped is four categories, showing 
# which of the four sets of passive options the respondent was offered 
aggregate(randomdraw6 ~ randomdraw6_grouped, el, range) #just check the grouping is right
el_compliers_absonly <- subset(el,respondent_category == "Complier")[,c(
	"randomdraw6_grouped","lc1","bring_up","pta","assemble",
	"abs_passive_option_lc1","abs_passive_option_bring_up",
	"abs_passive_option_pta","abs_passive_option_assemble",
	"treatment")] #Make temp matrix of absentee conative data only for compliers


#create table for control
el_compliers_absonly_control <- el_compliers_absonly[grep("absenteeism",el_compliers_absonly$treatment, invert=TRUE),]
col1 <- c(
	mean(subset(el_compliers_absonly_control, abs_passive_option_lc1=="tutor")$lc1),
	mean(subset(el_compliers_absonly_control, abs_passive_option_lc1=="headmaster")$lc1),
	mean(subset(el_compliers_absonly_control, abs_passive_option_lc1=="wait")$lc1),
	mean(subset(el_compliers_absonly_control, abs_passive_option_lc1=="send")$lc1))
col2 <- c(
	mean(subset(el_compliers_absonly_control, abs_passive_option_bring_up=="tutor")$bring_up),
	mean(subset(el_compliers_absonly_control, abs_passive_option_bring_up=="headmaster")$bring_up),
	mean(subset(el_compliers_absonly_control, abs_passive_option_bring_up=="wait")$bring_up),
	mean(subset(el_compliers_absonly_control, abs_passive_option_bring_up=="send")$bring_up))
col3 <- c(
	mean(subset(el_compliers_absonly_control, abs_passive_option_pta=="tutor")$pta),
	mean(subset(el_compliers_absonly_control, abs_passive_option_pta=="headmaster")$pta),
	mean(subset(el_compliers_absonly_control, abs_passive_option_pta=="wait")$pta),
	mean(subset(el_compliers_absonly_control, abs_passive_option_pta=="send")$pta))
col4 <- c(
	mean(subset(el_compliers_absonly_control, abs_passive_option_assemble=="tutor")$assemble),
	mean(subset(el_compliers_absonly_control, abs_passive_option_assemble=="headmaster")$assemble),
	mean(subset(el_compliers_absonly_control, abs_passive_option_assemble=="wait")$assemble),
	mean(subset(el_compliers_absonly_control, abs_passive_option_assemble=="send")$assemble))
action_df_el_control <- data.frame(cbind(col1,col2,col3,col4))
action_df_el_control <- cbind(Passive_Option,action_df_el_control)
action_df_el_control$treatment <- "control"
rm(col1,col2,col3,col4)


#create table for treatment
el_compliers_absonly_treatment <- el_compliers_absonly[grep("absenteeism",el_compliers_absonly$treatment),]
col1 <- c(
	mean(subset(el_compliers_absonly_treatment, abs_passive_option_lc1=="tutor")$lc1),
	mean(subset(el_compliers_absonly_treatment, abs_passive_option_lc1=="headmaster")$lc1),
	mean(subset(el_compliers_absonly_treatment, abs_passive_option_lc1=="wait")$lc1),
	mean(subset(el_compliers_absonly_treatment, abs_passive_option_lc1=="send")$lc1))
col2 <- c(
	mean(subset(el_compliers_absonly_treatment, abs_passive_option_bring_up=="tutor")$bring_up),
	mean(subset(el_compliers_absonly_treatment, abs_passive_option_bring_up=="headmaster")$bring_up),
	mean(subset(el_compliers_absonly_treatment, abs_passive_option_bring_up=="wait")$bring_up),
	mean(subset(el_compliers_absonly_treatment, abs_passive_option_bring_up=="send")$bring_up))
col3 <- c(
	mean(subset(el_compliers_absonly_treatment, abs_passive_option_pta=="tutor")$pta),
	mean(subset(el_compliers_absonly_treatment, abs_passive_option_pta=="headmaster")$pta),
	mean(subset(el_compliers_absonly_treatment, abs_passive_option_pta=="wait")$pta),
	mean(subset(el_compliers_absonly_treatment, abs_passive_option_pta=="send")$pta))
col4 <- c(
	mean(subset(el_compliers_absonly_treatment, abs_passive_option_assemble=="tutor")$assemble),
	mean(subset(el_compliers_absonly_treatment, abs_passive_option_assemble=="headmaster")$assemble),
	mean(subset(el_compliers_absonly_treatment, abs_passive_option_assemble=="wait")$assemble),
	mean(subset(el_compliers_absonly_treatment, abs_passive_option_assemble=="send")$assemble))
action_df_el_treatment <- data.frame(cbind(col1,col2,col3,col4))
action_df_el_treatment <- cbind(Passive_Option,action_df_el_treatment)
action_df_el_treatment$treatment <- "treatment"
rm(col1,col2,col3,col4)

rm(el_compliers_absonly,el_compliers_absonly_control,el_compliers_absonly_treatment)

##MIDLINE
#Subset midline data to compliers only and relevant variables, note that randomdraw6_grouped is four categories, showing 
# which of the four sets of passive options the respondent was offered 
aggregate(randomdraw6_ml ~ randomdraw6_grouped_ml, el, range) #just check the grouping is right
ml_compliers_absonly <- subset(el,respondent_category == "Complier")[,c(
	"randomdraw6_grouped_ml","lc1_ml","bring_up_ml","pta_ml","assemble_ml",
	"abs_passive_option_lc1_ml","abs_passive_option_bring_up_ml",
	"abs_passive_option_pta_ml","abs_passive_option_assemble_ml",
	"treatment")] #Make temp matrix of absentee conative data only for compliers
#create table for control
ml_compliers_absonly_control <- ml_compliers_absonly[grep("absenteeism",ml_compliers_absonly$treatment, invert=TRUE),]
col1 <- c(
	mean(subset(ml_compliers_absonly_control, abs_passive_option_lc1_ml=="tutor")$lc1),
	mean(subset(ml_compliers_absonly_control, abs_passive_option_lc1_ml=="headmaster")$lc1),
	mean(subset(ml_compliers_absonly_control, abs_passive_option_lc1_ml=="wait")$lc1),
	mean(subset(ml_compliers_absonly_control, abs_passive_option_lc1_ml=="send")$lc1))
col2 <- c(
	mean(subset(ml_compliers_absonly_control, abs_passive_option_bring_up_ml=="tutor")$bring_up),
	mean(subset(ml_compliers_absonly_control, abs_passive_option_bring_up_ml=="headmaster")$bring_up),
	mean(subset(ml_compliers_absonly_control, abs_passive_option_bring_up_ml=="wait")$bring_up),
	mean(subset(ml_compliers_absonly_control, abs_passive_option_bring_up_ml=="send")$bring_up))
col3 <- c(
	mean(subset(ml_compliers_absonly_control, abs_passive_option_pta_ml=="tutor")$pta),
	mean(subset(ml_compliers_absonly_control, abs_passive_option_pta_ml=="headmaster")$pta),
	mean(subset(ml_compliers_absonly_control, abs_passive_option_pta_ml=="wait")$pta),
	mean(subset(ml_compliers_absonly_control, abs_passive_option_pta_ml=="send")$pta))
col4 <- c(
	mean(subset(ml_compliers_absonly_control, abs_passive_option_assemble_ml=="tutor")$assemble),
	mean(subset(ml_compliers_absonly_control, abs_passive_option_assemble_ml=="headmaster")$assemble),
	mean(subset(ml_compliers_absonly_control, abs_passive_option_assemble_ml=="wait")$assemble),
	mean(subset(ml_compliers_absonly_control, abs_passive_option_assemble_ml=="send")$assemble))
action_df_ml_control <- data.frame(cbind(col1,col2,col3,col4))
action_df_ml_control$treatment <- "control"
action_df_ml_control <- cbind(Passive_Option,action_df_ml_control)
rm(col1,col2,col3,col4)

#create table for treatment
ml_compliers_absonly_treatment <- ml_compliers_absonly[grep("absenteeism",ml_compliers_absonly$treatment),]
col1 <- c(
	mean(subset(ml_compliers_absonly_treatment, abs_passive_option_lc1_ml=="tutor")$lc1),
	mean(subset(ml_compliers_absonly_treatment, abs_passive_option_lc1_ml=="headmaster")$lc1),
	mean(subset(ml_compliers_absonly_treatment, abs_passive_option_lc1_ml=="wait")$lc1),
	mean(subset(ml_compliers_absonly_treatment, abs_passive_option_lc1_ml=="send")$lc1))
col2 <- c(
	mean(subset(ml_compliers_absonly_treatment, abs_passive_option_bring_up_ml=="tutor")$bring_up),
	mean(subset(ml_compliers_absonly_treatment, abs_passive_option_bring_up_ml=="headmaster")$bring_up),
	mean(subset(ml_compliers_absonly_treatment, abs_passive_option_bring_up_ml=="wait")$bring_up),
	mean(subset(ml_compliers_absonly_treatment, abs_passive_option_bring_up_ml=="send")$bring_up))
col3 <- c(
	mean(subset(ml_compliers_absonly_treatment, abs_passive_option_pta_ml=="tutor")$pta),
	mean(subset(ml_compliers_absonly_treatment, abs_passive_option_pta_ml=="headmaster")$pta),
	mean(subset(ml_compliers_absonly_treatment, abs_passive_option_pta_ml=="wait")$pta),
	mean(subset(ml_compliers_absonly_treatment, abs_passive_option_pta_ml=="send")$pta))
col4 <- c(
	mean(subset(ml_compliers_absonly_treatment, abs_passive_option_assemble_ml=="tutor")$assemble),
	mean(subset(ml_compliers_absonly_treatment, abs_passive_option_assemble_ml=="headmaster")$assemble),
	mean(subset(ml_compliers_absonly_treatment, abs_passive_option_assemble_ml=="wait")$assemble),
	mean(subset(ml_compliers_absonly_treatment, abs_passive_option_assemble_ml=="send")$assemble))
action_df_ml_treatment <- data.frame(cbind(col1,col2,col3,col4))
action_df_ml_treatment$treatment <- "treatment"
action_df_ml_treatment <- cbind(Passive_Option,action_df_ml_treatment)
rm(col1,col2,col3,col4)

rm(ml_compliers_absonly,ml_compliers_absonly_control,ml_compliers_absonly_treatment)


###make tables ready for publication
action_df_el_treatment$treatment <- NULL
action_df_el_control$treatment <- NULL
action_df_ml_treatment$treatment <- NULL
action_df_ml_control$treatment <- NULL

action_df_el_treatment$Passive_Option <- NULL
action_df_el_control$Passive_Option <- NULL
action_df_ml_treatment$Passive_Option <- NULL
action_df_ml_control$Passive_Option <- NULL

rownames(action_df_el_treatment) <- c("Find a tutor","Ask headmaster","Wait","Neighbouring village")
rownames(action_df_el_control) <- c("Find a tutor","Ask headmaster","Wait","Neighbouring village")
rownames(action_df_ml_treatment) <- c("Find a tutor","Ask headmaster","Wait","Neighbouring village")
rownames(action_df_ml_control) <- c("Find a tutor","Ask headmaster","Wait","Neighbouring village")

colnames(action_df_el_treatment) <- c("Involve LC1 Chair","Tell village","Use PTA","Assemble group")
colnames(action_df_el_control) <- c("Involve LC1 Chair","Tell village","Use PTA","Assemble group")
colnames(action_df_ml_treatment) <- c("Involve LC1 Chair","Tell village","Use PTA","Assemble group")
colnames(action_df_ml_control) <- c("Involve LC1 Chair","Tell village","Use PTA","Assemble group")

###make latex tables
sink("03_tables/ABS_conative_attitudes_matrix_elT.tex")
print(xtable(action_df_el_treatment, digits=2, caption = "Conative attitudes among compliers in field experiment - Endline, treatment group (N = 474)", label = "table:conative_attitudes_matrix_elT"))
sink()

sink("03_tables/ABS_conative_attitudes_matrix_elC.tex")
print(xtable(action_df_el_control, digits=2, caption = "Conative attitudes among compliers in field experiment - Endline, control group (N = 567)", label = "table:conative_attitudes_matrix_elC"))
sink()

sink("03_tables/ABS_conative_attitudes_matrix_mlT.tex")
print(xtable(action_df_ml_treatment, digits=2, caption = "Conative attitudes among compliers in field experiment - Midline, treatment group (N = 474)", label = "table:conative_attitudes_matrix_mlT"))
sink()

sink("03_tables/ABS_conative_attitudes_matrix_mlC.tex")
print(xtable(action_df_ml_control, digits=2, caption = "Conative attitudes among compliers in field experiment - Midline, control group (N = 567)", label = "table:conative_attitudes_matrix_mlC"))
sink()

